
package com.example.admin.yuejian_22.Fragment;


import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v4.app.Fragment;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast;

import com.example.admin.yuejian_22.Adapter.CommentAdapter;
import com.example.admin.yuejian_22.Bean.CommentBean;
import com.example.admin.yuejian_22.Bean.PhotoBean;
import com.example.admin.yuejian_22.Listener.UserListener;
import com.example.admin.yuejian_22.Model.UserModel;
import com.example.admin.yuejian_22.R;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;

/**
 * A simple {@link Fragment} subclass.
 */
public class CommentFragment extends Fragment {
    public RecyclerView recyclerView;
    private View view = null;
    private String id;
    UserListener userListener = new UserListener() {
        @Override
        public void onResponse(Object beanobject) {

//            List<CommentBean> list = new ArrayList<CommentBean>();
//            for(int i=0;i< ((List<CommentBean>)beanobject).size();i++)
//            {
//                if(((List<CommentBean>)beanobject).get(i).getId().equals(id)){
//                    list.add(((List<CommentBean>)beanobject).get(i));
//                }
//            }

            recyclerView.setAdapter(new CommentAdapter(getActivity(),((List<CommentBean>)beanobject)));
        }

        @Override
        public void onFail(String msg) {
            Toast.makeText(getActivity(), ""+msg, Toast.LENGTH_SHORT).show();
        }

    };
    public void initRecyclerView(View view) {
        recyclerView = (RecyclerView) view.findViewById(R.id.photodetail_commentlist);
        recyclerView.setLayoutManager(new LinearLayoutManager(this.getActivity()));
        recyclerView.setItemAnimator(new DefaultItemAnimator());
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        view =  inflater.inflate(R.layout.fragment_comment, container, false);
        initRecyclerView(view);
        Intent intent = getActivity().getIntent();
        id = intent.getStringExtra("shaitu_id");
        Toast.makeText(getActivity(), id, Toast.LENGTH_SHORT).show();
        UserModel userModel = new UserModel();
        userModel.getCommentlist(userListener);
        return view;
    }


}

